<template>
  <div>
    <!-- 大客户订单提报 -->
    <TopFilter
      :list="topFilterList"
      :cols="3"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
      :labelWidth="110"
    ></TopFilter>

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      columnsRef="zjContractFiling"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => this.columns = columns"
    >
      <template slot="controls" slot-scope="props">
        <multiuse-button  size="small" type="primary" @click="addHandle(2)" icon="el-icon-plus">新 增</multiuse-button>
      </template>
    </FilterTable>
    <Drawer
      :visible.sync="emmitVisible"
      :title="'合同编辑'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
      width="72%"
    >
      <emitModel  :rowData="formData" @close="emitcloseHandler" />
    </Drawer>

    <Drawer
      :visible.sync="addVisible"
      :title="'合同新增'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
      width="72%"
    >
      <addModel  :rowData="formData" @close="emitcloseHandler" />
    </Drawer>
    <Drawer
      :visible.sync="detailVisible"
      :title="'合同详情'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
      width="72%"
    >
      <detailModel  :rowData="formData" @close="emitcloseHandler" />
    </Drawer>

  </div>
</template>
<script>
import emitModel from './emitModel'
import addModel from './addModel'
import detailModel from './detailModel'
export default {
  name:'TemplateDistribution',
  data(){
    this.BaseTable=null;
    return{
      topFilterList:this.createdFrom(),
      columns:this.createdTable(),
      fetchParams:{

      },
      fetchApi:()=>{},
      formData:{},
      emmitVisible:false,
      issearch:false,
      detailVisible:false,
      addVisible:false,
    }
  },
  components: {
    emitModel,
    detailModel,
    addModel
  },
  mounted(){
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created(){

  },
  methods:{
    createdFrom(){
      return [
        {
          type: 'INPUT',
          label: '买受人(乙方)',
          fieldName: 'msr',
          placeholder: '请选择',
          itemList:[]
        },
        {
          type: 'INPUT',
          label: '合同名称',
          fieldName: 'htmc',
          placeholder: '请选择',
        },
        {
          type: 'SELECT',
          label: '交车类型',
          fieldName: 'jclx',
          placeholder: '请选择',
          itemList:[]
        },
        {
          type: 'INPUT',
          label: '项目名称',
          fieldName: 'xmmc',
          placeholder: '请选择',
        },


        {
          type: 'RANGE_DATE',
          label: '合同生效日期',
          fieldName: 'htsxrq',
          placeholder: '请选择',
          initialValue:[]
        },

      ]
    },
    createdTable(){
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 50,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button  size="mini" type="text" onClick={() => this.editHandle(props.row,1)}>
                  编辑
                </multiuse-button>
                <el-divider direction="vertical" />
                <multiuse-button  size="mini" type="text" onClick={() => this.editHandle(props.row,2)}>
                  详情
                </multiuse-button>

              </div>
            );
          }
        },
        {
          title: '项目名称',
          dataIndex: 'xmmc',
          sorter: true,
          filter: true,
          filterType: 'input',
        },

        {
          title: '合同名称',
          dataIndex: 'htmc',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '合同编号',
          dataIndex: 'htbh',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '资金类型',
          dataIndex: 'zjlx',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '交车类型',
          dataIndex: 'jclx',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '合同生效日期',
          dataIndex: 'htsxrq',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '收车地址',
          dataIndex: 'scdz',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '合同名称',
          dataIndex: 'htmc',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '订购总数量',
          dataIndex: 'dgzsl',
          sorter: true,
          filter: true,
          filterType: 'input',
        },


      ]
    },
    selectChangeHandle(row){

    },
    seacherFun(){
      this.issearch=true;
    },
    addHandle(data){
      this.addVisible=true
    },
    changeHandle(params){
      this.fetchParams=Object.assign({},this.fetchParams,params)
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    async editHandle(data,type){
      if(type==1){
        this.emmitVisible=true
      }else if(type==2){
        this.detailVisible=true;
      }else if(type==3){
        await this.$confirm('是否进行提报?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        }).then(async () => {

        })
        .catch(()=>{})
      }else{
        await this.$confirm('是否确定删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(async () => {

      })
      .catch(()=>{})
      }

    },
    selectChangeHandle(val){

    },
    emitcloseHandler(){
      this.visible=false
      this.fetchParams=Object.assign({},this.fetchParams,params)
    }
  }
}
</script>
